import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class Client {
        public static void enviar(String pacote) {
                try {
                	String pacoteResto;
                	int i=0;
                	int n=0;
                	boolean check=false;
                        // Retrieve the ServerName
                        InetAddress serverAddr = InetAddress.getByName("192.168.1.105");
                       
                        //Log.d("UDP", "C: Connecting...");
                        /* Create new UDP-Socket */
                        DatagramSocket socket = new DatagramSocket();
                 
                        /* Prepare some data to be sent. */
                        check=false;
                        byte[] outData = (pacote).getBytes();
                        /* Create UDP-packet with
                         * data & destination(url+port) */
                        DatagramPacket packet = new DatagramPacket(outData, outData.length,     serverAddr, 1236);
                        //Log.d("UDP", "C: Sending: '" + new String(outData) + "'");
                        /* Send out the packet */
                        while(!check){      //espera ate o Android confirmar que recebeu o pacote
                        socket.send(packet);
                        System.out.println((pacote).getBytes().length);
                        for(i=0;i<1000;i++){
                        	System.out.println(Server.message);
                        	System.out.println(pacote);
                        	if (Server.message!=null && Server.message.equals(pacote)) check=true;  //se message == pacote entao o android recebeu o pacote e mandou ele de volta pode continuar 
                        }
                        }
                        
                  
                        
                        //Log.d("UDP", "C: Sent.");
                        //Log.d("UDP", "C: Done.");
                } catch (Exception e) {
                        //Log.e("UDP", "C: Error", e);
                }
        }
}